fix: impute NaN before variable-selection steps in stats.py#313
Open
drussellmrichie wants to merge 1 commit intolarsiusprime:masterfrom
Open
fix: impute NaN before variable-selection steps in stats.py#313drussellmrichie wants to merge 1 commit intolarsiusprime:masterfrom
drussellmrichie wants to merge 1 commit intolarsiusprime:masterfrom
Conversation
sklearn (ElasticNet) and statsmodels (OLS/VIF) raise errors when input features contain NaN values. This is triggered in practice when a dataset uses LightGBM's native NaN-handling (e.g. sparse binary indicators like "has_garage" or "has_fireplace" where NaN means "not recorded") and runs the variable-selection pre-pass before LightGBM training. The fix adds median imputation of NaN to the top of each of the four variable-selection functions: - calc_elastic_net_regularization - calc_p_values_recursive_drop - calc_t_values_recursive_drop - calc_vif_recursive_drop Imputation is scoped to these pre-passes only: LightGBM training still receives the real NaN values and handles them natively at each split. A UserWarning is emitted listing the affected columns so the user are aware. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
Thank you for your contribution. I affirm that this contributor has signed the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
sklearn (
ElasticNet) and statsmodels (OLS/VIF) raise errors when input features containNaNvalues. This is triggered when a dataset uses LightGBM native NaN-handling -- e.g. sparse binary indicators likehas_garagewhereNaNmeans "not recorded" -- and the variable-selection pre-pass runs before LightGBM training.Errors seen:
ValueError: Input X contains NaN(ElasticNet / sklearn)MissingDataError: exog contains inf or nans(statsmodels OLS)Fix
Add median imputation of
NaNto the top of each of the four variable-selection functions:calc_elastic_net_regularizationcalc_p_values_recursive_dropcalc_t_values_recursive_dropcalc_vif_recursive_dropImputation is scoped to these pre-passes only: LightGBM training still receives the real
NaNvalues and handles them natively at each split. AUserWarningis emitted listing the affected columns. Median imputation is a neutral choice for a variable-selection screen and does not bias which variables survive the screen.